<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<#include '/common/head.html'>
	<script type="text/javascript">
		var $dg , $window, $obj={} ;
		$(function() {
			$dg = $('#dg').datagrid({
				title: '用户管理',
				url: '/user/list', 
				method: 'GET', nowrap: true, striped: true, singleSelect: false,
				checkbox: true, pagination: true, pageSize: 30, pageList: [30,40,50,100,200,500,1000],
				autoRowHeight: true, fit: true, border: false, rownumbers: true, rownumberWidth: 40, toolbar: "#toolbars", 
				remoteSort: true, sortName: 'id', sortOrder: 'desc', queryParams: {},
				frozenColumns: [[
					{title: 'ID', field: 'id', hidden: true},
					{field: 'ck', checkbox:true},
					{title: '用户名称', field: 'realName', width: 100},
					{title: '登录账号', field: 'username', width: 100, sortable: true}
				]],
				columns: [[
					{title: '性别', field: 'gender', width: 60, align: 'center', sortable: true, formatter: function(value, row, index) {
						return value==1?'男':'女';
					}},
					{title: '电子邮箱', field: 'email', width: 200},
					{title: '手机号码', field: 'mobile', width: 110},
					{title: '账户类型', field: 'type', width: 90, align: 'center', formatter: function(value, row, index) {
						if(value==1) return '<span style="color:red">超级管理员</span>';
						else if(value==2) return '<span style="color:orange">普通管理员</span>';
						else if(value==3) return '<span style="color:green">普通操作员</span>';
						else return '-';
					}},
					{title: '状态', field: 'status', width: 60, align: 'center', formatter: function(value, row, index) {
						if(value==true) return '<i class="fa fa-circle" style="color:#15db81"></i>';
						else return'<i class="fa fa-circle" style="color:gray"></i>';
					}},
					{title: '最后登录时间', field: 'lastLoginTime', width: 90, align: 'center', formatter: function(value, row, index) {
						return value != null && value != '' ? $.date.format(value, 'yyyy-MM-dd') : '';
					}},
					{title: '最后登录IP', field: 'lastLogin_ip', width: 100},
					{title: '是否修改过密码', field: 'isChnagePwd', width: 100, align: 'center', formatter: function(value, row, index) {
						if(value==true) return '是';
						else return '否';
					}},
					{title: '密码最后修改时间', field: 'changePwdTime', width: 130, align: 'center', formatter: function(value, row, index) {
						return value != null && value != '' ? $.date.format(value, 'yyyy-MM-dd HH:mm:ss') : '';
					}},
					{title: '备注信息', field: 'remarks', width: 400},
					{title: '创建时间', field: 'createTime', width: 130, align: 'center', sortable: true, formatter: function(value, row, index) {
						return value != null && value != '' ? $.date.format(value, 'yyyy-MM-dd HH:mm:ss') : '';
					}},
					{title: '创建者', field: 'createBy', width: 70},
					{title: '更新时间', field: 'updateTime', width: 130, align: 'center', sortable: true, formatter: function(value, row, index) {
						return value != null && value != '' ? $.date.format(value, 'yyyy-MM-dd HH:mm:ss') : '';
					}},
					{title: '更新者', field: 'updateBy', width: 70},
				]]
			});
		});
		
		$obj = {
			add: function() {
				$window = MM.addWindow({title: '添加', href: '/user/form', width: 600, height: 320});
			},
			del: function() {
				var ids = MM.getSelectionsIds('#dg') ;
				if(ids) {
					$.messager.confirm('删除确认', '确定要删除？', function(r) {
						if(r) {
							$.get('/user/delete/'+ids, function(result) {
								try {
									if(result.code == 200) {
										$obj.reload(); alertify.success(result.message);
									} else {
										alertify.warning(result.message);
									}
								} catch(e) {
									$.easyui.loaded(); console.error(e) ;
								}
							}, 'JSON').complete(function(){$.easyui.loaded();});
						}
					});
				} else {
					alertify.error('至少选择一条记录');
				}
			},
			update: function() {
				var row = $dg.datagrid('getSelected') ;
				if(null != row && row.id != "") {
					$window = MM.addWindow({title: '修改', href: '/user/form?id='+row.id, width: 600, height: 320});
				} else {
					alertify.error('请选择一条记录');
				}
			},
			reload: function() {
				$dg.datagrid('reload'); $dg.datagrid('clearSelections');$dg.datagrid('clearChecked');
			}
		}
	</script>
	
</head>

<body>
	<div id="dg">
		<div id="toolbars"> 
			<a onclick="$obj.add();" class="easyui-linkbutton" data-options="plain:true, iconCls:'icon-add'">添加</a> 
			<a onclick="$obj.update();" class="easyui-linkbutton" data-options="plain:true, iconCls:'icon-edit'">编辑</a> 
			<a onclick="$obj.del();" class="easyui-linkbutton" data-options="plain:true, iconCls:'icon-cancel'">删除</a> 
			<a onclick="$obj.reload();" class="easyui-linkbutton" data-options="plain:true, iconCls:'icon-reload'">刷新</a> 
		</div>
	</div>
</body>
</html>